class MouseEventHandler {
  constructor() {
    this._left = 0;
    this._top = 0;
    this._newLeft = 0;
    this._newTop = 0;
    this._mouseDown = false;
  }

  /**
   * 设置位移前的位置，并标记位移开始
   * @param left
   * @param top
   */
  set pos({ left, top }) {
    this._left = left;
    this._top = top;
    this._mouseDown = true;
  }

  /**
   * 设置位移后的位置
   * @param left
   * @param top
   */
  set newPos({ left, top }) {
    this._newLeft = left;
    this._newTop = top;
  }

  /**
   * 获取位移前后两点在坐标上的位移
   * @returns {{top: number, left: number}}
   */
  get diff() {
    return {
      left: this._newLeft - this._left,
      top: this._newTop - this._top
    }
  }

  /**
   * 重设位移前的位置
   */
  afterMove() {
    this._left = this._newLeft;
    this._top = this._newTop;
  }

  /**
   * 标记位移结束
   */
  reset() {
    this._mouseDown = false;
  }

  /**
   * 获取当前是否正在发生位移
   * @returns {boolean}
   */
  get mouseDown() {
    return this._mouseDown;
  }

}
